/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package movie.mb;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import movie.ejb.EjbFilm;
import movie.entity.Film;

/**
 *
 * @author admin
 */
@ManagedBean
@SessionScoped
public class MbFilm implements Serializable {

	@ManagedProperty(value = "#{mbLogin}")
	private MbLogin mbLogin;
	@EJB
	private EjbFilm ejbFilm;
	private List<Film> listFilm;
	private Film film;

	/**
	 * Creates a new instance of MbFilm
	 */
	public MbFilm() {
		System.out.print("Constructor: " + getClass().getName());
	}

	@PostConstruct
	public void postConstruct() {
		System.out.print("Post construct: " + getClass().getName());
	}

	public void prepareFilm(Film film) {
		if (film == null) {
			this.film = new Film(0);
		} else {
			this.film = film;
		}
	}

	public void deleteFilm() {
		ejbFilm.deleteFilm(film.getIdFilm());
	}
	// navigations==============================================

	public String navigationToFilmsOverview() {
		listFilm = ejbFilm.getListFilm();
		return "films-overview?faces-redirect=true";
	}

	public String navigationToFilmUpdate(Film film) {
		prepareFilm(film);
		return "film-update?faces-redirect=true";
	}
	//geters and seters===========================================

	public MbLogin getMbLogin() {
		return mbLogin;
	}
        public boolean isNewFilm() {
            return film.getIdFilm()==0;
        }

	public void setMbLogin(MbLogin mbLogin) {
		this.mbLogin = mbLogin;
	}

	public List<Film> getListFilm() {
		return listFilm;
	}

	public void setListFilm(List<Film> listFilm) {
		this.listFilm = listFilm;
	}

	public Film getFilm() {
		return film;
	}

	public void setFilm(Film film) {
		this.film = film;
	}
}
